package com.trippartner.client;

import com.google.gwt.event.logical.shared.ResizeEvent;
import com.google.gwt.event.logical.shared.ResizeHandler;
import com.google.gwt.user.client.ui.HasWidgets;
import com.google.web.bindery.event.shared.EventBus;
import com.trippartner.client.map.presenter.CartePresenter;
import com.trippartner.client.map.presenter.GeoPointDetailsPresenter;
import com.trippartner.client.menu.presenter.GlobalMenuPresenter;
import com.trippartner.client.pattern.MVPDisplay;
import com.trippartner.client.pattern.MVPPresenter;

public class MainPresenter extends MVPPresenter<MainPresenter.Display> {

	private GlobalMenuPresenter globalMenuPresenter;

	private CartePresenter cartePresenter;

	private GeoPointDetailsPresenter geoPointDetailsPresenter;
	
	public interface Display extends MVPDisplay {
		com.trippartner.client.menu.presenter.GlobalMenuPresenter.Display getGlobalMenuView();
		com.trippartner.client.map.presenter.CartePresenter.Display getCarteView();
		com.trippartner.client.map.presenter.GeoPointDetailsPresenter.Display getGeoPointDetailsView();
		String getMenuFixedHeight();
		int getGeoPointDetailsFixedWidthRatio();
		void resize();
	}

	public MainPresenter(final Display display, final EventBus eventBus) {
		super(display, eventBus);
	}

	protected void bind() {
	}

	@Override
	public void go(final HasWidgets container) {
		bind();
		globalMenuPresenter = new GlobalMenuPresenter(display.getGlobalMenuView(), eventBus);
		cartePresenter = new CartePresenter(display.getCarteView(), eventBus);
		geoPointDetailsPresenter = new GeoPointDetailsPresenter(display.getGeoPointDetailsView(), eventBus);
		container.add(display.asWidget());		
	}

	@Override
	protected void registerHandler() {
		eventBus.addHandler(ResizeEvent.getType(), new ResizeHandler() {
			public void onResize(ResizeEvent event) {
				display.resize();
			}
		});
	}

	public CartePresenter getCartePresenter() {
		return cartePresenter;
	}

	public GlobalMenuPresenter getGlobalMenuPresenter() {
		return globalMenuPresenter;
	}

	public GeoPointDetailsPresenter getGeoPointDetailsPresenter() {
		return geoPointDetailsPresenter;
	}

}
